/**
 * 工位管理-删除工位(非空闲状态)/解除关联
 */
import React, { memo, useState } from 'react';
import { withRouter } from 'umi';
import AuthComponent from '@/utils/auth/AuthComponent';
import Icon from '../Icon';
import DeleteStationModal from './DeleteStationModal';

function RelativeEmployee({ onRefresh, type, ...rest }) {
    const [modalVisible, setModalVisible] = useState(false);
    const isDelete = type === 'delete';
    return (
        <AuthComponent code={isDelete ? 'office:administration:adminManage:station:delete' : 'office:administration:adminManage:station:unLink'}>
            <Icon
                type={isDelete ? 'DeleteIcon' : 'listfunction_absence_icon_default'}
                title={isDelete ? '删除' : '解除关联'}
                onClick={() => { setModalVisible(true) }}
            />
            <DeleteStationModal
                title={isDelete ? '删除工位' : '解除工位'}
                visible={modalVisible}
                onCancel={() => { setModalVisible(false) }}
                onOk={() => {
                    setModalVisible(false);
                    onRefresh();
                }}
                type={type}
                {...rest}
            />
        </AuthComponent>
    );
}
export default withRouter(memo(RelativeEmployee));
